/*
 * DetectorConstruction.cc
 *
 *  Created on: 05.05.2011
 *      Author: ed
 */

#include "DetectorConstruction.hh"


#include "DetectorConstruction.hh"
#include "G4Material.hh"
#include "G4MaterialTable.hh"
#include "G4Element.hh"
#include "G4ElementTable.hh"
#include "G4LogicalBorderSurface.hh"
#include "G4LogicalSkinSurface.hh"
#include "G4Box.hh"
#include "G4LogicalVolume.hh"
#include "G4RotationMatrix.hh"
#include "G4ThreeVector.hh"
#include "G4Transform3D.hh"
#include "G4PVPlacement.hh"
#include "G4OpBoundaryProcess.hh"
#include "G4MultiFunctionalDetector.hh"
#include "G4PSTrackLength.hh"
#include "G4VPrimitiveScorer.hh"
#include "G4SDManager.hh"
#include "TrackerSD.hh"
class TrackerSD;
DetectorConstruction::DetectorConstruction() {
	// TODO Auto-generated constructor stub

}

DetectorConstruction::~DetectorConstruction() {
	// TODO Auto-generated destructor stub
}
G4VPhysicalVolume* DetectorConstruction::Construct()
{
	G4Element* N = new G4Element("Nitrogen", "N", 7 , 14.01*g/mole);
	G4Element* O = new G4Element("Oxygen"  , "O", 8 , 16.00*g/mole);

	G4Material* air = new G4Material("Air", 1.29*mg/cm3, 2);
	air->AddElement(N, 70.*perCent);
	air->AddElement(O, 30.*perCent);

	G4Element* H = new G4Element("Hydrogen", "H", 1 , 1.01*g/mole);

	G4Material* water = new G4Material("Water",  1.0*g/cm3, 2);
	water->AddElement(H, 2);
	water->AddElement(O, 1);

	G4double photonEnergy[1] = {1*eV};
	G4double refractiveIndex1[1] = {1};

	G4double refractiveIndex2[1] = {2};
	G4double absorption[1] = {5*cm};
	G4MaterialPropertiesTable* myMPT1 = new G4MaterialPropertiesTable();
	myMPT1->AddProperty("RINDEX", photonEnergy, refractiveIndex1,1);
	myMPT1->AddProperty("ABSLENGTH", photonEnergy, absorption,1);
	water->SetMaterialPropertiesTable(myMPT1);

	G4MaterialPropertiesTable* myMPT2 = new G4MaterialPropertiesTable();
	myMPT2->AddProperty("RINDEX", photonEnergy, refractiveIndex2, 1);
	air->SetMaterialPropertiesTable(myMPT2);

	G4Box* box1 = new G4Box("Box1",w*m,h*m,d*m);
	G4LogicalVolume* logVol1 = new G4LogicalVolume(box1,water,"logVol1");
	G4VPhysicalVolume* physVol1 = new G4PVPlacement(0,G4ThreeVector(),logVol1,"Vol1",0,false,0);



	/*G4Box* box2 = new G4Box("Bix2",w,h,d);
	G4LogicalVolume* logVol2 = new G4LogicalVolume(box2,water,"logVol2");
	G4VPhysicalVolume* physVol2 = new G4PVPlacement(0,G4ThreeVector(w*1.9,0,0),logVol2,"Vol2",logVol1,true,0);
	*/


	/*
	G4OpticalSurface* OpSurface = new G4OpticalSurface("name");

	G4LogicalBorderSurface* Surface = new
	  G4LogicalBorderSurface("name",physVol1,physVol2,OpSurface);

	G4double sigma_alpha = 0.1;

	OpSurface -> SetType(dielectric_dielectric);
	OpSurface -> SetModel(unified);
	OpSurface -> SetFinish(groundbackpainted);
	OpSurface -> SetSigmaAlpha(sigma_alpha);

	const G4int NUM = 2;

	G4double pp[NUM] = {1*eV, 4.144*eV};
	G4double specularlobe[NUM] = {0.0, 0.0};
	G4double specularspike[NUM] = {0.0, 0.0};
	G4double backscatter[NUM] = {0.0, 0.0};
	G4double rindex[NUM] = {0.0, 0.0};
	G4double reflectivity[NUM] = {0.5, 1};
	G4double efficiency[NUM] = {0.0, 0.0};

	G4MaterialPropertiesTable* SMPT = new G4MaterialPropertiesTable();

	SMPT -> AddProperty("RINDEX",pp,rindex,NUM);
	SMPT -> AddProperty("SPECULARLOBECONSTANT",pp,specularlobe,NUM);
	SMPT -> AddProperty("SPECULARSPIKECONSTANT",pp,specularspike,NUM);
	SMPT -> AddProperty("BACKSCATTERCONSTANT",pp,backscatter,NUM);
	SMPT -> AddProperty("REFLECTIVITY",pp,reflectivity,NUM);
	SMPT -> AddProperty("EFFICIENCY",pp,efficiency,NUM);

	OpSurface -> SetMaterialPropertiesTable(SMPT);

	*/
	G4SDManager *sdMan = G4SDManager::GetSDMpointer();
	if(sdMan)
	{
		TrackerSD* trackerSD = new TrackerSD("Detector");
		sdMan->AddNewDetector(trackerSD);
		logVol1->SetSensitiveDetector(trackerSD);
	}
	return physVol1;
}
